<template>
  <div class="addGoodsAdd">
    <el-dialog
      :visible.sync="dialogFormVisible"
      :title="topTitle"
      :show-close="true"
      :modal-append-to-body="false"
      :close-on-click-modal="false"
      @close="closeDialog"
    >
      <!-- 点击上面的新增 -->
      <div class="newAddEdit" style="margin: 0 auto; width: 80%">
        <div class="newAddConfig">
          <el-form
            :model="addGoodsData"
            ref="addGoodsData"
            class="demo-dynamic"
            label-width="191px"
          >
            <el-form-item
              prop="title"
              label="奖池名称"
              :rules="[
                { required: true, message: '请输入奖池名称', trigger: 'blur' },
              ]"
            >
              <el-input
                placeholder="请输入奖池名称"
                v-model="addGoodsData.title"
                style="width: 63%"
              ></el-input>
            </el-form-item>
            <el-form-item
              label="可抽奖日期"
              :rules="[
                {
                  required: true,
                  message: '请选择可抽奖日期',
                  trigger: 'blur',
                },
              ]"
            >
              <!-- <el-date-picker
                v-model="prizeDate"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                value-format="yyyy-MM-dd"
                @change="changeDate"
                end-placeholder="结束日期"
              >
              </el-date-picker> -->
              <el-date-picker
                v-model="prizeDate"
                type="datetimerange"
                value-format="yyyy-MM-dd HH:mm:ss"
                range-separator="-"
                @change="changeDate"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              >
              </el-date-picker>
            </el-form-item>
            <el-form-item style="margin-top: 40px">
              <el-button type="danger" @click="closeDialog()">取消</el-button>
              <el-button
                type="primary"
                @click="confirmAddConfig('addGoodsData')"
                >确认</el-button
              >
            </el-form-item>
          </el-form>
        </div>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import requestAxios from "../../../http";
export default {
  name: "addGoodsAdd",
  data() {
    return {
      dialogFormVisible: true, //背景遮罩层
      topTitle: "奖池编辑", //弹出框上面的标题
      prizeDate: [],
      addGoodsData: {
        onlineTime: "",
        offlineTime: "",
        title: "",
      }, //点击新增下一个页面要展示出来的数据 //要编辑的列表部分的内容
    };
  },
  props: ["addOrEdit", "editAddgoodss"],
  mounted() {
    this.addGoodsData = this.$props.editAddgoodss;
    this.prizeDate[0] = this.$props.editAddgoodss.onlineTime;
    this.prizeDate[1] = this.$props.editAddgoodss.offlineTime;
  },

  methods: {
    //选择时间
    changeDate(value) {
      console.log("改变时间", value);
      if (value && value.length > 1) {
        this.addGoodsData.onlineTime = value[0] + " 00:00:00";
        this.addGoodsData.offlineTime = value[1] + " 23:59:59";
      } else {
        this.addGoodsData.onlineTime = "";
        this.addGoodsData.offlineTime = "";
      }
    },
    closeDialog(done) {
      console.log("关闭弹窗", done);
      this.$parent.addOrEdit = false;
    },

    //新增确定调取接口
    confirmAddConfig(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          let obj = this.addGoodsData;
          requestAxios
            .fetchPost(
              "/api/v2.1/exchange/store/management/prize/virtualGroup/update",
              obj,
              {
                headers: {},
              }
            )
            .then((data) => {
              if (data.status == 200 && data.data.success) {
                console.log("奖池编辑", data.data);
                //新增成功
                this.$emit("getAddGoodsList");
                this.tip(true, "编辑奖池成功!");
                this.$parent.addOrEdit = 0;
              } else {
                console.log("=====奖池编辑成功=====", data);
                this.tip(false, data.data.errorMsg);
              }
            })
            .catch((err) => {
              console.log(err);
            });
        } else {
          // 获取图形验证码
          this.$message.error("请完善奖品信息！");
          return false;
        }
      });
    },
    //提示的通用方法
    tip(state, text) {
      if (state) {
        this.$message({
          showClose: true,
          message: text,
          type: "success",
        });
      } else {
        this.$message({
          showClose: true,
          message: text,
          type: "error",
        });
      }
    },
  },
};
</script>
<style>
.addGoodsAdd .close_boun {
  position: absolute;
  font-size: 26px;
  color: white;
  top: 15px;
  right: 10px;
}
.configBounDele {
  margin-right: 46px;
}
.el-icon-error {
  margin-left: 50px;
  font-size: 17px;
  color: rgb(133, 131, 131);
}
.enterInput {
  width: 51%;
  outline: none;
  padding-left: 7px;
}
.disApperInput {
  margin-left: 13%;
}
.disApperInput input {
  outline: none;
}
.closeSelect {
  width: 27%;
  height: 22px;
  padding-left: 7px;
  display: inline-block;
  margin-right: 10%;
  position: relative;
  margin-bottom: 10px;
}
.selectListX {
  /* width: 70%; */
  margin-left: 12%;
}
.selectListX .el-icon-close {
  position: absolute;
  top: 5px;
  left: 130px;
}
.selectListX .closeSelect:nth-child(2n) {
  margin-right: 0;
}
.affirmAddCancel .el-button--danger:focus,
.affirmAddCancel .el-button--danger {
  width: 93px;
  background: white;
  color: #d4af82;
  border: 1px solid #d4af82;
  margin-right: 20px;
}
.clickUpload {
  display: block;
  width: 93px;
  color: #d4af82;
  font-size: 12px;
  height: 28px;
  line-height: 28px;
  border-radius: 4px;
  border: 1px solid #d4af82;
  text-align: center;
  margin-left: 22%;
}
.affirmAddCancel {
  margin-top: 40px;
  text-align: center;
}
.affirmAddCancel .el-button--primary {
  width: 93px;
  /* background: #d4af82; */
  border: none;
}
/* .el-dialog__header {
  background: #77b3a1; 
   text-align: center;
} */
/* .el-dialog__title {
  color: white;
} */
.el-dialog__headerbtn .el-dialog__close {
  /* color: white; */
  font-size: 26px;
}

/*
传图页面的样式
*/
.uploadPicList {
  height: 100px;
  display: flex;
}
.picCommodity {
  height: 100px;
  display: inline-block;
  width: 380px;
  position: relative;
}
.uploadPicName {
  display: inline-block;
  margin-left: 100px;
  width: 150px;
  line-height: 100px;
}
.picCommodity .imgDelete {
  /* color: #d4af82; */
  position: absolute;
  left: -66px;
  top: -9px;
}
.picCommodity img {
  position: absolute;
  left: 0px;
  top: 0px;
}
/* 确定和取消按钮 */
.configUploadPage .affirmAddCancel .el-button--danger:focus,
.configUploadPage .affirmAddCancel .el-button--danger {
  width: 93px;
  background: white;
  /* color: #d4af82;
  border: 1px solid #d4af82; */
  margin-right: 20px;
}
.configUploadPage .affirmAddCancel .el-button--primary {
  width: 93px;
  /* background: #d4af82; */
  border: none;
}
.configUploadPage {
  width: 80%;
  margin: 0 auto;
}
</style>
